package com.iedu.demo.lgq.mapper;

import com.iedu.demo.lgq.entity.TbUserAddress;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;


@Mapper
public interface TbUserAddressMapper {
    @Insert("INSERT INTO tb_user_address (user_name, region_id, city_id, address, tel, real_name) " +
            "VALUES (#{userName}, #{regionId}, #{cityId}, #{address}, #{tel}, #{realName})")
    void insert(TbUserAddress address);
    // 根据用户姓名查找所有收货地址
    @Select("SELECT * FROM tb_user_address WHERE user_name = #{userName}")
    List<TbUserAddress> findByUserName(@Param("userName") String userName);

    // 根据地址ID查找单个收货地址
    @Select("SELECT * FROM tb_user_address WHERE id = #{addressId}")
    TbUserAddress findById(@Param("addressId") Long addressId);

    // 更新用户地址信息
    @Update("UPDATE tb_user_address SET province = #{province}, city = #{city}, " +
            "district = #{district}, address = #{address} WHERE id = #{id}")
    void update(TbUserAddress address);

    // 删除收货地址
    @Delete("DELETE FROM tb_user_address WHERE id = #{id}")
    void deleteById(@Param("id") Long id);

}
